package com.donleo.fastdfs.controller;

import com.donleo.fastdfs.service.FastDfsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author liangd
 * @since 2021-01-25 17:41
 */
@RestController
@RequestMapping("/file")
public class FastDfsController {

    @Autowired
    private FastDfsService fastDfsService;

    /**
     * 上传文件返回id
     */
    @PostMapping("/myUpload")
    public Integer upload(MultipartFile myFile) throws IOException {
        return fastDfsService.upload(myFile);
    }

    /**
     * 根据图片id(mysql中的id)
     */
    @GetMapping("/fastDownload/{id}")
    public void download(@PathVariable Integer id, HttpServletResponse response) throws IOException {
        fastDfsService.download(id, response);
    }
}
